package com.woniuxy.carlife.carlifeuserclient.Util;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @author qk
 * @ClassName:TokenInterceptor
 * @Description:
 * @date 2021/4/15 17:34
 **/
@Component
public class TokenInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        if (token != null && !token.trim().equals("")) {
            template.header("token", token);
        }

    }
}
